Flash memory devices are being used in more devices as their storage size increases and they become faster. Currently, flash memory is used as a medium for storing code segments. Code segments cannot be divided and stored in multiple locations within memory, rather they must be stored in a contiguous block of memory. The addition and removal of code segments to and from flash creates unique issues. A new code segment must have enough room in flash memory to be stored contiguously, similar to segmentation issues with any type of media. However, unlike other media, stored code segments have high overhead when they are moved around to create enough empty space to make room for a new code segment. Due to the physics of flash memory, moving written data around requires relatively significant effort and time. A good algorithm would limit the amount of data movement to efficiently allow code segment storage.